package channel

import (
	"fmt"
)

func calcSquares(number int, squareOp chan int) {
	sum := 0
	for number != 0 {
		digit := number % 10
		sum += digit * digit
		number = number / 10
	}
	squareOp <- sum
}

func calcCubes(number int, cubeOp chan int) {
	sum := 0
	for number != 0 {
		digit := number % 10
		sum += digit * digit * digit
		number = number / 10
	}

	cubeOp <- sum
}

func main() {
	number := 589

	sqrch := make(chan int)
	cubech := make(chan int)

	go calcSquares(number, sqrch)
	go calcCubes(number, cubech)

	squares, cubes := <-sqrch, <-cubech
	fmt.Println("final output", squares, cubes)
}
